package com.raising.sc.core.util.common;

import com.raising.sc.core.util.base.BaseUtils;

import java.lang.reflect.Field;

/**
 * JSON工具类
 * @author GaoYuan
 * @date 2018/4/11 上午8:18
 */
public class JsonUtils extends BaseUtils{

    /**
     * json格式化
     */
    public static String jsonFormat(Object obj){
        Class c = obj.getClass();
        Field fields[] = c.getDeclaredFields();
        StringBuffer sb = new StringBuffer();
        sb.append("{");
        try {
            for(int i=0; i<fields.length; i++){
                String name = fields[i].getName();
                fields[i].setAccessible(true);
                String value = fields[i].get(obj).toString();
                sb.append("'"+name+"':"+"'"+value+"',");
            }
        } catch (Exception e) {
        }
        sb.append("}");
        return sb.toString();
    }
}
